<?php
// +----------------------------------------------------------------------
// | CoreThink [ Simple Efficient Excellent ]
// +----------------------------------------------------------------------
// | Copyright (c) 2014 http://www.corethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: jry <598821125@qq.com> <http://www.corethink.cn>
// +----------------------------------------------------------------------
namespace Admin\Controller;
use Think\Controller;
/**
 * 后台标签控制器
 * @author jry <598821125@qq.com>
 */
class CustomizeController extends AdminController{
    /**
     * 标签列表
     * @author jry <598821125@qq.com>
     */
    public function index(){
        //搜索
        $keyword = I('keyword', '', 'string');
        $condition = array('like','%'.$keyword.'%');
        $map['name|size|color'] = array($condition, $condition, $condition,'_multi'=>true);
        $data_list = D('Customize')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('id desc')->select();
        $page = new \Common\Util\Page(D('Customize')->where($map)->count(), C('ADMIN_PAGE_ROWS'));

        $attr['title']="發貨";
        $attr['class']="ajax-get label label-info";
        $attr['href']=U('status',array('id'=>__data_id__));
        
        //使用Builder快速建立列表页面。
        $builder = new \Common\Builder\ListBuilder();
        $builder->setMetaTitle('定制列表') //设置页面标题
                ->addTopButton('delete')  //添加删除按钮
                ->setSearch('请输入商品名稱/尺寸/顏色', U('index'))
                ->addTableColumn('contact', '聯繫人')
                ->addTableColumn('address', '地址')
                ->addTableColumn('tel', '電話')
                ->addTableColumn('name', '商品名稱')
                ->addTableColumn('color', '顏色')
                ->addTableColumn('size', '尺寸')
                ->addTableColumn('img', '圖片','picture')
                ->addTableColumn('status', '發貨狀態','status')
                ->addTableColumn('right_button', '操作', 'btn')
                ->setTableDataList($data_list) //数据列表
                ->setTableDataPage($page->show()) //数据列表分页
                ->addRightButton('self',$attr)
                ->addRightButton('edit')   //添加编辑按钮
                ->addRightButton('delete') //添加删除按钮
                ->display();
    }
    
     public function status(){
         $id=I('get.id');
        $info['id']=$id;
        $info['status']=1;
        $data=M('Customize')->save($info);
        if($data){
            $this->success('發貨成功！');
        }else{
            $this->error('商品已發貨！');
        }
    }


    /**
     * 编辑标签
     * @author jry <598821125@qq.com>
     */
    public function edit($id){
        if(IS_POST){
            $tag_object = D('Customize');
            $data = $tag_object->create();
            if($data){
                if($tag_object->save()!== false){
                    $this->success('更新成功', U('index'));
                }else{
                    $this->error('更新失败');
                }
            }else{
                $this->error($tag_object->getError());
            }
        }else{
            //使用FormBuilder快速建立表单页面。
            $builder = new \Common\Builder\FormBuilder();
            $builder->setMetaTitle('编辑時裝') //设置页面标题
                    ->setPostUrl(U('edit')) //设置表单提交地址
                    ->addFormItem('id', 'hidden', 'ID', 'ID')
                    ->addFormItem('name', 'text', '商品名稱',null,null,null,"disabled=disabled")
                    ->addFormItem('describe', 'textarea', '商品描述',null,null,null,"disabled=disabled")
                    ->addFormItem('color', 'text', '顏色',null,null,null,"disabled=disabled")
                    ->addFormItem('size', 'text', '尺寸',null,null,null,"disabled=disabled")
                    ->addFormItem('status', 'text', '發貨狀態','0:未發貨|1：已發貨')
                    ->setFormData(D('Customize')->find($id))
                    ->display();
        }
    }

}
